mui.plusReady(dopull);
function dopull(){
	if(mui.os.android){
		$(".mui-scroll").addClass("android_pull");
	}
}

mui.init({
	swipeBack:false, //右滑关闭功能
	pullRefresh : {
    container:"#iControlHasdoPull",//下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
    down : {
      //contentdown : "下拉可以刷新",//可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
      contentover : "释放立即刷新",//可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
      //contentrefresh : "正在刷新...",//可选，正在刷新状态时，下拉刷新控件上显示的标题内容
      callback :pullfreshList //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
    }
   }
});
if(window.plus){
    plusReady();
}else{
    document.addEventListener('plusready',plusReady,false);
}
//全局系统编号
var pubxtbh = "";
//全局功能编号
var pubgnbh = "";
//全局项目编号
var pubxmbh = "";
//首次点击事件
var first = null;
function plusReady(){
	var current=plus.webview.currentWebview();
	pubxtbh = current.xtbh;
	pubgnbh = current.gnbh;
	pubxmbh = current.xmbh;
	loadListData(pubxtbh,pubgnbh,pubxmbh);
	//返回首页
	document.getElementById('home').addEventListener('tap', function() {
	var h=plus.webview.getWebviewById('mainpage');
	plus.webview.show(h);
	mui.fire(h,'tabClick',{tabId:'defaultTab'});
	});
	//添加自定义事件 供外部调用
	document.addEventListener('loadListDataHasDo', function(event) {
		loadListData(pubxtbh,pubgnbh,pubxmbh);
  	});
}
/*//下边是实现全选/全不选
function checked(){
	document.getElementById("btn_select").style.backgroundColor ="#6D6D72";
	setTimeout("btn_color_chg('check')",100);
	var a = document.getElementsByTagName("input");
	if(a.length==0){
		mui.toast("对不起，没有可选项");
		return;
	}
	if(a[0].checked){
		for(var i = 0;i<a.length;i++){
			if(a[i].type == "checkbox") a[i].checked = false;
			document.getElementById("allselect").innerHTML ="<i class=\"fa fa-check-circle pan_color_darkorange\"></i>&nbsp;全选";
		}
	}
	else{
		for(var i = 0;i<a.length;i++){
			if(a[i].type == "checkbox") a[i].checked = true;
			document.getElementById("allselect").innerHTML ="<i class=\"fa fa-circle-o pan_color_darkorange\"></i>&nbsp;全不选";
		}
	}
}*/
/*//切换按钮颜色
function btn_color_chg(btn){
	if(btn=="check"){
		document.getElementById("btn_select").style.backgroundColor ="#FFFFFF";
	}
		document.getElementById("btn_approval").style.backgroundColor ="#FFFFFF";
}*/
/*//批量撤回
function allreturn(){
	document.getElementById("btn_approval").style.backgroundColor ="#6D6D72";
	setTimeout("btn_color_chg('approval')",100);
	var a = document.getElementsByTagName("input");
	var num = 0;
	var param =pubgnbh;
	for(var i=0;i<a.length;i++){
		if(a[i].type == "checkbox"&& a[i].checked==true){
			num++;
			param =param+ ":" + a[i].value;
		}
	}
	//console.log(param);
	if(num<=0){
		mui.toast("请选择");
	}else{
		var token = plus.storage.getItem("token");
		if(token==null||token==""){
			return;
		}else{
			mui.ajax(baseServerAdrr+'/mobile/getNkspCancel',{
		    data: {
		   		token:token,
		   		params:param
		   },
		   dataType:'json',//服务器返回json格式数据
		   type:'post',//HTTP请求类型
		   timeout:30000,//超时时间设置为10秒；
		   success:function(data){
		   	   if(data.code =="success"){
		   	   	 mui.toast(data.message);
		   	   	 loadListData(pubxtbh,pubgnbh,pubxmbh);
		   	   }else{
		   	   	mui.toast(data.message);
		   	   }
	           
		    },
		    error:function(xhr,type,errorThrown){
			   //异常处理；
			   mui.toast('服务器异常登录失败! iControlHasDoList.js');
		    }
			});
		}
	}
}*/
//列表点击事件
function listclick(param,xtbh,gnid){
	/*var detailWebview = plus.webview.getWebviewById("iControlHasDoDetail");
   if(detailWebview!=undefined){
   	plus.webview.close(detailWebview);
   }*/
   var listview=mui.openWindow({url:param,id:"iControlHasDoDetail",extras:{xtbh:xtbh,gnid:gnid,gnbh:pubgnbh},createNew:true,waiting:{autoShow:false}});
}

//加载自身页面信息
function loadListData(xtbh,gnbh,xmbh) {
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/mobile/getYbGNList',{
	   data: {
	   		token:token,
	   		xtbh:xtbh,
	   		gnbh:gnbh,
	   		xmbh:xmbh
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		   panUtil.ajaxLoding.stop();
		   if(data.code=='success'){
              var sys = data.message;
              var table = document.body.querySelector('.mui-table-view');
              table.innerHTML='';
              for(var i=0;i<sys.length;i++){
              	 var sy=sys[i];
              	 var sylist = sy.lists;
              	 for(var j=0;j<sylist.length;j++){
              	 	var arrlist = sylist[j];
              	 	//document.getElementById("iControlList_title").innerHTML = arrlist.gnmc;
              	 	var data = arrlist.data;
              	 	
              	 	if(xmbh.indexOf("8")==0){
              	 		document.getElementById("iControlList_title").innerHTML = data[0].F_SQDWMC+"--内控审批";
              	 	}else{
              	 		document.getElementById("iControlList_title").innerHTML = data[0].F_PHXMMC+"--内控审批";
              	 	}
              	 	
              	 	for(var m=0;i<data.length;m++){
              	 		var arrdata = data[m];
              	 		var li = document.createElement('li');
                 		//li.className = 'mui-table-view-cell mui-checkbox mui-left';
              	 		//li.innerHTML ='<input name="checkbox" type="checkbox" id="'+arrdata.F_NKSPDH+'" value="'+arrdata.F_NKSPDH+'" style="line-height: 80px;"><div class="mui-table"><div class="mui-table-cell mui-col-xs-10" ><h4 class="mui-ellipsis">'+arrdata.F_SQDWMC+'</h4><h5>'+arrdata.F_SKDWMC+'</h5><p class="mui-h6 mui-ellipsis">单项审批金额：<span id="money" style="color: #555555;">'+arrdata.F_SQJE+'</span> 万元 &nbsp; 预计利息：<span id="interest" style="color: #555555;">'+arrdata.F_ZJLX+'</span> 万元</p></div><div class="mui-table-cell mui-col-xs-2 mui-text-right" ><a class="mui-navigate-right" href="javascript:void(0)" onclick="listclick(\''+arrdata.ext1+'\',\''+sy.xtbh+'\',\''+arrdata.F_NKSPDH+'\')" style="display: block;"></a></div></div>';
              	 		li.className = 'mui-table-view-cell mui-left';
              	 		/*li.innerHTML ='<a class="mui-navigate-right" href="javascript:void(0)" onclick="listclick(\''+arrdata.ext1+'\',\''+sy.xtbh+'\',\''+arrdata.F_NKSPDH+'\')" ><div class="mui-table"><h4 class="mui-ellipsis">'+arrdata.F_SQDWMC+'</h4><h5>'+arrdata.F_SKDWMC+'</h5><p class="mui-h6 mui-ellipsis">单项审批金额：<span id="money" style="color: #555555;">'+arrdata.F_SQJE+'</span> 万元 &nbsp; 预计利息：<span id="interest" style="color: #555555;">'+arrdata.F_ZJLX+'</span> 万元</p></div></a>';*/
              	 		//li.innerHTML ='<div ><a class="mui-navigate-right" href="javascript:void(0)" onclick="listclick(\''+arrdata.ext1+'\',\''+sy.xtbh+'\',\''+arrdata.F_NKSPDH+'\')" style="color:black;" ><div class="mui-table"><div class="mui-table-cell mui-col-xs-12" ><h4 style="font-weight:900">'+arrdata.F_SQDWMC+'&nbsp;付给</h4><span>'+arrdata.F_SKDWMC+'，总金额：'+arrdata.F_HJJE+'万元，单项金额：'+arrdata.F_SQJE+'万元，利息：'+arrdata.F_ZJLX+'万元</span></div></div></a><div>';
              	 		
              	 		
              	 		
              	 		
              	 		if(xmbh.indexOf("8")==0){
              	 		    li.innerHTML ='<a class="mui-navigate-right" href="javascript:void(0)" onclick="listclick(\''+arrdata.ext1+'\',\''+sy.xtbh+'\',\''+arrdata.F_NKSPDH+'\')" ><div class="mui-table"><h4 class="mui-ellipsis">'+arrdata.F_PHXMMC+'</h4><h5>'+arrdata.F_SKDWMC+'</h5><p class="mui-h6 mui-ellipsis">单项审批金额：<span id="money" style="color: #555555;">'+arrdata.F_SQJE+'</span> 万元 &nbsp; 预计利息：<span id="interest" style="color: #555555;">'+arrdata.F_ZJLX+'</span> 万元</p></div></a>';
              	 	    }else{
              	 		    li.innerHTML ='<a class="mui-navigate-right" href="javascript:void(0)" onclick="listclick(\''+arrdata.ext1+'\',\''+sy.xtbh+'\',\''+arrdata.F_NKSPDH+'\')" ><div class="mui-table"><h4 class="mui-ellipsis">'+arrdata.F_SQDWMC+'</h4><h5>'+arrdata.F_SKDWMC+'</h5><p class="mui-h6 mui-ellipsis">单项审批金额：<span id="money" style="color: #555555;">'+arrdata.F_SQJE+'</span> 万元 &nbsp; 预计利息：<span id="interest" style="color: #555555;">'+arrdata.F_ZJLX+'</span> 万元</p></div></a>';
              	 	    }
              	 	
              	 		table.appendChild(li);
              	 	}
              	 }
              }
		   }else{
		   	    mui.toast(data.message);
		   	    setTimeout(function(){
		   	    	panUtil.ReLogin();
		   	    },1000);
		   }
	    },
	    error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! iControlHasDoList.js');
	    }
		});
	}
}
//重写返回事件
var old_back = mui.back;
mui.back = function(){
   var h=plus.webview.getWebviewById("iControlSelect");
   mui.fire(h,"loadIControlSelect");
   //继续当前页面原有返回逻辑
   old_back();
}

function pullfreshList() {
    //console.log("sss");   //这块是为了测试
     //业务逻辑代码，该地方是 获取当前页面对象。调用自己写好的自定义事件、
    panUtil.setCloseTime(first,3000,'您刷新的太快了啊，休息下再刷新吧。',self);
    //注意，加载完新数据后，必须执行如下代码，注意：若为ajax请求，则需将如下代码放置在处理完ajax响应数据之后
     mui('#iControlHasdoPull').pullRefresh().endPulldownToRefresh();
}

function self(){
	loadListData(pubxtbh,pubgnbh,pubxmbh);
}